package controllers;

import java.util.List;

import com.google.gson.Gson;
import com.google.gson.JsonObject;

import models.GuestbookEntry;
import play.mvc.Controller;

public class ApiGuestbookEntry extends Controller {

    public static void all() {
        
    	List<GuestbookEntry> posts = GuestbookEntry.all().fetch();
    	notFoundIfNull(posts);
    	
    	renderJSON(posts);  	
    	
    }
    

    public static void get(Long id) {
        
    	GuestbookEntry post = GuestbookEntry.all().filter("id", id).get();
    	notFoundIfNull(post);
    	
    	renderJSON(post);  	
   	
    }
    
    
    public static void add(String body) {
    	
    	GuestbookEntry guestbookEntry 
    		= new Gson().fromJson(body, GuestbookEntry.class);   	
    	
    	notFoundIfNull(guestbookEntry);
    	
    	guestbookEntry.save();
    	
    }

}